﻿function AddFavorite(surl, sTitle) {
    try {
        if (surl)
            surl = this.href;
        if (sTitle)
            sTitle = document.title;
        var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
        var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf("360se") > -1) {
            alert("由于360浏览器功能限制，请按 Ctrl+D 手动收藏！");
        }
        else if (ua.indexOf("msie 8") > -1) {
            window.external.AddToFavoritesBar(url, title); //IE8
        }
        else if (document.all) {
            window.external.addFavorite(surl, sTitle);
        } else if (window.sidebar) {
            window.sidebar.addPanel(sTitle, surl, "");
        } else {
            alert('您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~');
        }
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, surl, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
//设为首页 <a onclick="SetHome(this,window.location)">设为首页</a>
function SetHome(obj, vrl) {
    var url = this.href;
    try {
        this.style.behavior = "url(#default#homepage)";
        this.setHomePage(url);
    } catch (e) {
        if (document.all) {
            document.body.style.behavior = "url(#default#homepage)";
            document.body.setHomePage(url);
        } else if (window.sidebar) {
            if (window.netscape) {
                try {
                    window.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                } catch (e) {
                    alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
                    return false;
                }
            }
            var prefs = window.Components.classes["@mozilla.org/preferences-service;1"].getService(window.Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', url);
        } else {
            //alert('您的浏览器不支持自动设置首页, 使用浏览器菜单或在浏览器地址栏输入“chrome://settings/browser”手动设置!');
            window.location = 'http://support.google.com/chrome/bin/answer.py?hl=zh-Hans&answer=95314';
        }
    }
    return false;
}